package hn.cch.microservice.service_consumer_user.controller;


import hn.cch.microservice.service_consumer_user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

//加载配置文件路径
@PropertySource(value = {"classpath:application.properties"})
@RestController
public class UserController {

    //读取配置文件参数
    @Value(value = "${rest.user.url}")
    private String restUserUrl;

    @Autowired
    private RestTemplate restTemplate;

    @Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate;
    }

    @GetMapping(value = "/{id}")
    public User user(@PathVariable Long id) {
        return restTemplate.getForObject(restUserUrl + id, User.class);
    }

}
